﻿USE master 
GO
CREATE DATABASE SuperSurvey
GO
USE SuperSurvey
GO
CREATE TABLE AccountInformation
(	
	Username nvarchar(100) PRIMARY KEY,
	[Password] nvarchar(100) ,
	FullName nvarchar(100) ,
	Birthday smalldatetime ,
	Email nvarchar(100),
	[Address] nvarchar(100)			
)
GO
 CREATE TABLE AccountLogin
 (
	Username nvarchar(100) FOREIGN KEY REFERENCES AccountInformation(Username),
	[Status] int DEFAULT 0 CHECK([Status] = 1 OR [Status] = 0),
	TimeOnline smalldatetime,
	TimeOffline smalldatetime,
	IP varchar(100)	
 )
 GO
 CREATE TABLE Friend
 (
	MyID nvarchar(100) FOREIGN KEY REFERENCES AccountInformation(Username),
	FriendID nvarchar(100) FOREIGN KEY REFERENCES AccountInformation(Username),
	[Status] int DEFAULT 0 CHECK([Status] = 1 OR [Status] = 0),
	constraint pk_Friend primary key (MyID, FriendID)
 )
 GO
 CREATE TABLE SurveyDetail
 (
	[subject] nvarchar(200),
	SurveyID int IDENTITY(1,1) PRIMARY KEY,
	UserName nvarchar(100) FOREIGN KEY REFERENCES AccountInformation(Username),
	Theme nvarchar(300),
	TimeCreate smalldatetime,
	--
 )
CREATE TABLE Recipient(
	SurveyID int FOREIGN KEY REFERENCES SurveyDetail(SurveyID),
	UserNameRecipient nvarchar(100) FOREIGN KEY REFERENCES AccountInformation(Username)
)

 CREATE TABLE Question (
	QuestionID int IDENTITY(1,1) PRIMARY KEY,
	SurveyID int FOREIGN KEY REFERENCES SurveyDetail(SurveyID),
	QuestionContent nvarchar(max), 
	QuestionType varchar(20) DEFAULT 'Text' CHECK(QuestionType ='Checkbox' or QuestionType = 'Radio' or QuestionType = 'Text')
	
 )
 CREATE TABLE Ansewr(
	AnsewrID int IDENTITY(1,1) PRIMARY KEY ,
	QuestionID int FOREIGN KEY REFERENCES Question(QuestionID),
	AnsewrContent nvarchar(max),

 )
 -- tao  bang  de luu khi  nguoi dung tra  loi 


  